#!/bin/bash
###SHELLPACK preamble sparsetruncate-bench 0

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam	--nr-directories	SPARSETRUNCATE_DIRECTORIES
###SHELLPACK parseargParam	--nr-files		SPARSETRUNCATE_FILES
###SHELLPACK parseargParam	--filesize		SPARSETRUNCATE_FILESIZE
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required_continue sparsetruncate-${VERSION}
cd $SHELLPACK_SOURCES/sparsetruncate-${VERSION}-installed ||
	die Failed to change to benchmark directory

###SHELLPACK init_only_start
echo Initialising files
# <dir> <dirs> <files> <fsize> <initonly>
rm -rf $SHELLPACK_DATA/sparsetruncate
mkdir -p $SHELLPACK_DATA/sparsetruncate
./sparsetruncate $SHELLPACK_DATA/sparsetruncate $SPARSETRUNCATE_DIRECTORIES $SPARSETRUNCATE_FILES $SPARSETRUNCATE_FILESIZE 1
if [ $? -ne 0 ]; then
	die Failed to initialise $SHELLPACK_DATA
fi
###SHELLPACK init_only_end

echo Truncating
monitor_pre_hook $LOGDIR_RESULTS $P
$TIME_CMD -o $LOGDIR_RESULTS/time											\
	./sparsetruncate $SHELLPACK_DATA/sparsetruncate $SPARSETRUNCATE_DIRECTORIES $SPARSETRUNCATE_FILES $SPARSETRUNCATE_FILESIZE 0	\
		> $LOGDIR_RESULTS/truncate.log 2>&1
monitor_post_hook $LOGDIR_RESULTS $P

exit $SHELLPACK_SUCCESS
